/**
 * 
 */
package com.java.test.messagecenter.controller;

import com.java.test.controller.BaseController;
import com.java.test.messagecenter.dto.HorseNoticeInfo;
import com.java.test.messagecenter.dto.NoticeInfo;
import com.java.test.messagecenter.dto.PushMessageInfo;
import com.java.test.messagecenter.service.MessageCenterService;
import com.java.test.util.HttpErrorCode;
import com.java.test.util.JsonResult;
import com.java.test.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/message")
public class MessageCenterController extends BaseController{

	@Autowired
	MessageCenterService messageCenterService;

	/**
	 * 推送消息列表
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/messageList")
	public JsonResult paytypeList(@RequestBody PageInfo<PushMessageInfo> info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			PageInfo<PushMessageInfo> list = messageCenterService.selectpushmessageList(info);
			if (list == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 查询单个推送
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/selectpushmessagebyId")
	public JsonResult selectpushmessagebyId(@RequestBody PushMessageInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			PushMessageInfo infos = messageCenterService.selectpushmessagebyId(info);
			if (infos == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(infos);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}
	
	/**
	 * 添加单个推送消息
	 * @param info
	 * @return
	 */
	@RequestMapping("/insertpushmessageInfo")
	public JsonResult insertpushmessageInfo(@RequestBody PushMessageInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = messageCenterService.insertpushmessageInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}
	
	/**
	 * 公告列表
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/pushnoticeList")
	public JsonResult pushnoticeList(@RequestBody PageInfo<NoticeInfo> info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			PageInfo<NoticeInfo> list = messageCenterService.selectpushnoticeList(info);
			if (list == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 查询单个公告
	 * @param infos
	 * @return
	 */
	@RequestMapping("/selectnoticeInfo")
	public JsonResult selectnoticeInfo(@RequestBody NoticeInfo infos) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			NoticeInfo info = messageCenterService.selectnoticeInfo(infos);
			if (info == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(info);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}
	
	
	/**
	 * 更新公告
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/updatepushnoticeInfo")
	public JsonResult updatepushnoticeInfo(@RequestBody NoticeInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = messageCenterService.updatepushnoticeInfo(info);
			if (i < 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 刪除公告
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/deletepushnoticeInfo")
	public JsonResult deletepushnoticeInfo(@RequestBody List<NoticeInfo> info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int ids[] = info.stream().mapToInt(NoticeInfo::getId).toArray();
			int i = messageCenterService.deletepushnoticeInfo(ids);
			if (i < 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 添加公告
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/addpushnoticeInfo")
	public JsonResult addpushnoticeInfo(@RequestBody NoticeInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = messageCenterService.addpushnoticeInfo(info);
			if (i < 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	
	
	
	
	// -- 跑马灯
	/**
	 *  pao跑马灯公告列表
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/horsenoticeList")
	public JsonResult horsenoticeList(@RequestBody PageInfo<HorseNoticeInfo> info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			PageInfo<HorseNoticeInfo> list = messageCenterService.selecthorsenoticePage(info);
			if (list == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 跑马灯公告
	 * @param infos
	 * @return
	 */
	@RequestMapping("/selecthorsenoticeInfo")
	public JsonResult selecthorsenoticeInfo(@RequestBody HorseNoticeInfo infos) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			HorseNoticeInfo info = messageCenterService.selecthorsenoticeInfo(infos);
			if (info == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(info);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}
	
	
	/**
	 * 刪除跑马灯
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/deletehorsenoticeInfos")
	public JsonResult deletehorsenoticeInfos(@RequestBody List<HorseNoticeInfo> info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			long ids[] = info.stream().mapToLong(HorseNoticeInfo::getId).toArray();
			int i = messageCenterService.deletehorsenoticeInfo(ids);
			if (i < 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}


	/**
	 * 刪除跑马灯
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/inserthorsenoticeInfo")
	public JsonResult inserthorsenoticeInfo(@RequestBody HorseNoticeInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = messageCenterService.inserthorsenoticeInfo(info);
			if (i < 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}
	
	
	/**
	 * 更新跑马灯
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/updatehorsenoticeInfo")
	public JsonResult updatehorsenoticeInfo(@RequestBody HorseNoticeInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = messageCenterService.updatehorsenoticeInfo(info);
			if (i < 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}
	
}
